
local MyMapAddon = LibStub("AceAddon-3.0"):NewAddon("layer", "AceEvent-3.0")

function MyMapAddon:OnInitialize()
    self.mapText = Minimap:CreateFontString(nil, "OVERLAY")
    self.mapText:SetPoint("TOPRIGHT", Minimap, "TOPRIGHT", -5, -5)
    self.mapText:SetFont("Fonts\\ARIALN.TTF", 12, "OUTLINE")
    -- self.mapText:SetText("位面1")
end

function MyMapAddon:OnEnable()
    self:RegisterEvent("PLAYER_ENTERING_WORLD", "UpdateMapInfo")
    self:RegisterEvent("ZONE_CHANGED", "UpdateMapInfo")
end

function MyMapAddon:UpdateMapInfo()
    local mapID = C_Map.GetBestMapForUnit("player")
    local mapInfo = C_Map.GetMapInfo(mapID)
    if mapInfo then
        local playerName = UnitName("player")
        if playerName and mapInfo.mapType == Enum.UIMapType.Continent then
            local mapName = mapInfo.name
            self.mapText:SetText(playerName .. "位于" .. mapName)
        end
    end
end